package com.example.demo.clid;

import com.example.demo.dao1.ClassDao;
import com.example.demo.dao1.StuDao;
import com.example.demo.dao1.StuJpaDao;
import com.example.demo.entity.Stus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class Hello {
    @Resource
    ClassDao classDao;
    @Resource
    StuDao stuDao;
    @Resource
    StuJpaDao stuJpaDao;

    public Hello() {
    }

    @GetMapping({"/insert"})
    public String insert(String name, String sex, int classId) {
        int result = this.stuDao.insert(name, sex, classId);
        return result == 1 ? "插入成功" : "插入失败";
    }

    @GetMapping({"/update"})
    public String update(String name, int id) {
        int result = this.stuDao.update(name, id);
        return result == 1 ? "更新成功" : "更新失败";
    }

    @GetMapping({"/updateStu"})
    public String updateStu(int id, String name) {
        int result = this.stuDao.update(name, id);
        return result == 1 ? "更新成功" : "更新失败";
    }

    @GetMapping({"/delete"})
    public String delete(int id) {
        int result = this.stuDao.delete(id);
        return result == 1 ? "删除成功" : "删除失败";
    }

    @GetMapping({"/getAll"})
    public List<Stus> getAll() {
        List<Stus> result = this.stuDao.getAll();
        return result;
    }
}
